class AdminController < ApplicationController
  
  before_filter :admin_required, :only => [:index, :send_email]
  before_filter :set_current_menu_and_title
  
  def index
    @current_menu = :nil
  end
  
  def send_email
    all_user = params[:all_user]
    email_recipient = params[:email_recipient]
    email_title = params[:email_title]
    email_content = params[:email_content]
    
    if all_user == "on"
      User.find(:all).each do |u|
        EmailQueue.create(:subject => email_title, :content => bbcode2html(email_content), :recipient => u.email, :content_type => "text/html")
      end
    else
      email_recipient.split(',').each do |r|
        EmailQueue.create(:subject => email_title, :content => bbcode2html(email_content), :recipient => r, :content_type => "text/html")
      end
    end
    redirect_to "/"
  end
  
  private
    def set_current_menu_and_title
      @admin = true
      @title = "后台管理"
    end

end